package com.lc1993929.mr.rating;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.codehaus.jackson.map.ObjectMapper;

import java.io.IOException;

/**
 * Created by LiuChang on 2017/11/14/014.
 */
public class UserRatingTopNMapper extends Mapper<LongWritable, Text, Text, RateBean> {
    ObjectMapper objectMapper;
    Text text = new Text();

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        objectMapper = new ObjectMapper();

    }

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        RateBean rateBean = objectMapper.readValue(value.toString(), RateBean.class);
        text.set(rateBean.getUid());
        context.write(text, rateBean);
    }
}
